#include "headController.h"
#include "math.h"

//--------------------------------------------------------------
headController::headController() {
	
	cout << "---constructor---photoBoothController---" << endl;
	
}

//--------------------------------------------------------------
headController::~headController() {
	
	cout << "---destructor---photoBoothController---" << endl;
	
}

//--------------------------------------------------------------
void headController::setup() {
	
	cout << "---setup---" << endl;

	//--positioning (parts overruled in testApp.cpp)
	setDirection( headController::DIRECTION_STOP );
	setPosition(200, 100);
	setMovePixels(3);
	setSize(50);	

}

//--------------------------------------------------------------
void headController::update() {

	moveHead();

}

//--------------------------------------------------------------
void headController::draw() {

    
	
	//--DEV circle
	ofPushStyle();
	ofSetColor(255, 0, 0);
	ofCircle(getPosition().x, getPosition().y, 50);
	ofPopStyle();
	

}

//--------------------------------------------------------------
void headController::keyPressed(int key) {
	
	if (key == OF_KEY_DOWN) {
		setDirection( headController::DIRECTION_DOWN );
	}
	
	if (key == OF_KEY_UP) {
		setDirection( headController::DIRECTION_UP );
	}
	
	if (key == OF_KEY_RIGHT) {
		setDirection( headController::DIRECTION_RIGHT );
	}
	
	if (key == OF_KEY_LEFT) {
		setDirection( headController::DIRECTION_LEFT );
	}
      
}





//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
void headController::moveHead(){
	
	//cout << getDirection() << endl;
	
	if ( getDirection() != headController::DIRECTION_STOP) {
		
		switch ( getDirection() ) {
			case headController::DIRECTION_DOWN:
				if ( getPosition().y >= ofGetHeight() - movePixels - size) {
					setDirection( headController::DIRECTION_STOP );
				} else {
					position.y += movePixels;
				}
				break;
			case headController::DIRECTION_LEFT:
				if ( getPosition().x <= movePixels + size) {
					setDirection( headController::DIRECTION_STOP );
				} else {
					position.x -= movePixels;
				}
				break;
			case headController::DIRECTION_RIGHT:
				if ( getPosition().x >= ofGetWidth() - movePixels - size) {
					setDirection( headController::DIRECTION_STOP );
				} else {
					position.x += movePixels;
				}
				break;
			case headController::DIRECTION_UP:
				if ( getPosition().y <= movePixels + size) {
					setDirection( headController::DIRECTION_STOP );
				} else {
					position.y -= movePixels;
				}
				break;
			default:
				break;
		}
	} else {
		// @ STOP
	}
	
	
}

//--------------------------------------------------------------
//-SETTERS------------------------------------------------------
//--------------------------------------------------------------
void headController::setDirection(DIRECTION newDirection){
	moveDirection = newDirection;
}

//--------------------------------------------------------------
void headController::setPosition(int _x, int _y){

	//TODO: check if value is plausible
	
	position.set(_x, _y);

}

//--------------------------------------------------------------
void headController::setMovePixels(int _num_pixels){
	movePixels = _num_pixels;
}

//--------------------------------------------------------------
void headController::setSize(int _size){
	size = _size;
}


//--------------------------------------------------------------
//-GETTERS------------------------------------------------------
//--------------------------------------------------------------
ofPoint headController::getPosition(){
	return position;
}

//--------------------------------------------------------------
headController::DIRECTION headController::getDirection(){
	return moveDirection;
}




